package com.sanchunhui.psc.presenter

import com.sanchunhui.psc.data.protocol.ResponseInfo
import com.sanchunhui.psc.ext.excute
import com.sanchunhui.psc.presenter.view.TeamMembersView
import com.sanchunhui.psc.rx.BaseSubscriber
import com.sanchunhui.psc.service.ProjectTeamService
import com.sanchunhui.psc.service.TeamMemberService
import javax.inject.Inject

/**
 * @Author zyx
 * @Date 2021/7/13-9:08
 * @Dscribe
 */
class TeamMembersPresenter  @Inject constructor() : BasePresenter<TeamMembersView>() {

    @Inject
    lateinit var teamService: ProjectTeamService

    /*
        获取分组下所有成员
     */
    fun  getTeamMember(teamId:Int, token:String) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        teamService.getTeamMember(teamId, token).excute(object : BaseSubscriber<ResponseInfo>(mView) {
            override fun onNext(t: ResponseInfo) {
                mView.onGetTeamMemberResult(t)
            }
        }, lifecycleProvider)
    }

    /*
        设置指定分组负责⼈
     */
    fun setTeamLeader(teamId:Int, token:String, memberId:Int) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        teamService.setTeamLeader(teamId, token,memberId).excute(object : BaseSubscriber<Boolean>(mView) {
            override fun onNext(t: Boolean) {
                mView.onSetTeamLeaderResult(t)
            }
        }, lifecycleProvider)
    }

    /*
       移除项⽬（分组）中的成员
     */
    fun deleteMember(token:String, memberId:Int) {
        if (!checkNetWork()) {
            return
        }
        mView.showLoading()
        teamService.deleteMember(token,memberId).excute(object : BaseSubscriber<Boolean>(mView) {
            override fun onNext(t: Boolean) {
                mView.onDeleteMemberResult(t)
            }
        }, lifecycleProvider)
    }

    /*
        获取分组在线的成员ID
     */
    fun getOnlineMember(teamId: Int,token: String) {
        if (!checkNetWork()) {
            return
        }
//        mView.showLoading()
        teamService.getOnlineMember(teamId,token).excute(object : BaseSubscriber<MutableList<Char>>(mView) {
            override fun onNext(t: MutableList<Char>) {
                mView.onGetOnlineMemberResult(t)
            }

        }, lifecycleProvider )
    }

    /*
     获取所在或指定分组信息
   */
    fun  getProjectTeamInfo(teamId: Int, token:String) {
        if (!checkNetWork()) {
            return
        }
        teamService.getProjectTeamInfo(teamId,token).excute(object : BaseSubscriber<ResponseInfo>(mView) {
            override fun onNext(t: ResponseInfo) {
                mView.onGetProjectTeamInfoResult(t)
            }
        }, lifecycleProvider)
    }

}